$(function() {
    $('form').parsley();
    dynamicBinding();
    getAllResTeam();
});
//遍历所有resTeam输出到表格
function getAllResTeam() {
    let updateStr = "";
    let deleteStr = "";
    let columns = [
        {title: "序号", data: null,"render": function (data,type,row,meta) {
                return data=Number(meta.row)+Number(1);
            }},
        <!--String name, Long departmentId, Long type,String location,String eventType, Long strength,String category,String mainEquipment,String phone,Boolean isFullTime-->
        {title: "应急队伍名称", data: "name"},
        {title: "所属单位", data: "departmentId"},
        {title: "队伍类型", data: "type"},
        {title: "经度", data: "gpsX"},
        {title: "纬度", data: "gpsY"},
        {title: "适用事件类别", data: "eventType"},
        {title: "队伍人数", data: "strength"},
        {title: "队伍专长", data: "category"},
        {title: "主要设备", data: "mainEquipment"},
        {title: "值班电话", data: "phone"},
        {title: "是否全职", data: "isFullTime"},
        {title: "操作", data: "id","orderable": false, // 禁用排序
            "defaultContent": "","render": function (data,type,row,meta) {
                if (hasDeletePermission) {
                    deleteStr = "<button data-id=" + data + "  type='button' class='btn btn-danger data-delete'>删除</button>&emsp;"
                }
                if (hasUpdatePermission) {
                    updateStr = "<button data-id=" + data + " type='button' class='btn btn-info data-update' data-toggle='modal' data-target='#updateResTeamModal'>更新</button>";
                }
                return data = deleteStr+updateStr;}}
    ];
    let url ='/resTeam/getAllResTeam';
    dataTableInit(url,columns);
}
//动态绑定
function dynamicBinding() {
    //为所有的delete按钮绑定delete事件
    deleteBind( '/resTeam/deleteResTeam');
    //为所有的update按钮绑定update事件
    updateBind(  '#toUpdateResTeam', '/resTeam/updateResTeam', false, false, "#updateResTeamModal");
    //为所有的add按钮绑定add事件
    addBind('#toAddResTeam', '/resTeam/addResTeam', false, false, "#addResTeamModal");
    //为add模态框绑定消失事件-清空模态框中内容
    $('#addResTeamModal').on('hidden.bs.modal', function () {
        document.getElementById("toAddResTeam").reset();
    });
    //为update模态框绑定消失事件-清空模态框中内容
    $('#updateResTeamModal').on('hidden.bs.modal', function () {
        document.getElementById("toUpdateResTeam").reset();
    });
}
